package likou.jindian;

import java.util.Arrays;

/**
 * @author: Tangxz
 * @email: 1171702529@qq.com
 * @cate: 2021/01/12 09:57
 */
public class _10_01 {
    public static void main(String[] args) {
        System.out.println(Arrays.toString(merge(new int[]{1,2,3,0,0,0},3,new int[]{2,5,6},3)));
    }
    public static int[] merge(int[] A, int m, int[] B, int n) {
        int nowAI = 0;
        for(int i=0;i<n&&nowAI<n+m;i++){
            while(nowAI<i+m&&A[nowAI]<=B[i]){
                nowAI++;
            }
            if(nowAI==i+m){
                while(i<n){
                    A[nowAI++] = B[i];
                    i++;
                }
                break;
            }else{
                int temp = A[nowAI];
                A[nowAI] = B[i];
                B[i] = temp;
                i--;
            }
        }
        return A;
    }
}
